package FactoryDemo;

/**
 * Created by yexuan on 2018/3/30.
 * 简单工厂
 */
public class SimpleFactory
{
    int No;
    public SimpleFactory(int No){
        this.No = No;
    }
    public IProduct GetProduct()
    {
        switch (No) //根据产品标识生产产品
        {
            default:
                return new ProductA();
            case 1:
                return new ProductA();
            case 2:
                return new ProductB();
        }

    }

    public static void main(String[] args){
        new SimpleFactory(2);
    }
}

//产品A
class ProductA implements IProduct
        {
        //产品属性
        //......
        }

//产品B
class ProductB implements IProduct
        {
        //产品属性
        //......
        }
//产品接口
interface IProduct
{
    //产品方法
    //......
}
